package cn.hengzhu.main_manager.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import cn.hengzhu.main_manager.repository.dao.SysConstMapper;
import cn.hengzhu.main_manager.repository.domain.SysConst;
import cn.hengzhu.main_manager.repository.domain.SysConstExample;
import cn.hengzhu.main_manager.service.SysConstService;
import cn.hengzhu.main_manager.utils.HttpClientUtil;
import cn.hengzhu.main_manager.utils.config.xcx.WxConfig;


@Service
public class SysConstServiceImpl implements SysConstService{
	
	@Autowired
	private SysConstMapper sysConstMapper;

	@Override
	public String  updateAccessTokenByWXXcx() {
		String url = WxConfig.GET_TOKEN.replace("APPID", WxConfig.APPID).replace("APPSECRET", WxConfig.SECRET);
		String httpGet = HttpClientUtil.httpGet(url);
		JSONObject parseObject = JSONObject.parseObject(httpGet);
		System.out.println(parseObject);
		String access_token = (String) parseObject.get("access_token");
		SysConst record = new SysConst();
		SysConstExample example = new SysConstExample();
		record.setValue(access_token);
		example.createCriteria().andNameEqualTo(WxConfig.ACCESS_TOKEN);
		sysConstMapper.updateByExampleSelective(record, example);
		return access_token;
	}

}
